package powerpass;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author aaronfrost
 */

import java.sql.*;
public class PowerPassSQL {
    private Connection con = null;
    private Statement stmt = null;
    private ResultSet rs = null;
    private String database = "jdbc:mysql://db4free.net/slccpowerpass";
    private String dblogin = "cs2550";
    private String dbpass = "java2550";

    public PowerPassSQL()
    {


    }
    public ResultSet selectInfo(String SQL) throws SQLException
    {
        try {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection(database, dblogin, dbpass);
            } catch (SQLException e) {
                System.out.println("SQL Exception: "+ e.toString());
            } catch (ClassNotFoundException cE) {
                System.out.println("Class Not Found Exception: "+ cE.toString());
            }
            //SQL query command
            System.out.println(SQL);
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
            return rs;
        }
        finally
        {
            //con.close();
        }
    }
    public void insertInfo(String SQL) throws SQLException
    {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        boolean hadError = false;
        try {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection(database, dblogin, dbpass);
            } catch (SQLException e) {
                System.out.println("SQL Exception: "+ e.toString());
                hadError = true;
            } catch (ClassNotFoundException cE) {
                System.out.println("Class Not Found Exception: "+ cE.toString());
                hadError = true;
            }
            //SQL query command
            System.out.println("Had SQL Exception: "+hadError);
            System.out.println(SQL);
            stmt = con.createStatement();
            int queryresult = stmt.executeUpdate(SQL);
            System.out.println("Executed Query with Result: "+ queryresult);
        }
        finally
        {
            //con.close();
        }
    }
    public void updateInfo(String SQL) throws SQLException
    {
        insertInfo(SQL);
    }
    public void Close() throws SQLException
    {
        con.close(); //rs and stmt will autoclose with this closure
    
    }
}
